var express = require('express');
var router = express.Router();

//引入第二层函数
const {
    getCars2,
    getCarDetail2,
    searchCars2,
    add2,
    upDate2,
    upDateRemoved2
}=require("../service/car.js")
/* GET home page. */
//分页获取车辆
router.get("/getCars", async function (req, res, next) {
    const result = await getCars2(req.query);
    res.send(result)
});

//获取车辆详细信息,可以用于刷新获取状态
router.get("/carDetail",async function(req,res,next){
    // console.log("第一层"+req.body._id);
    const result=await getCarDetail2(req.query);
    res.send(result)
})

//搜索车辆
router.get("/search",async function(req,res,next){
    const result=await searchCars2(req.query);
    console.log("第一层"+result.message);
    
    res.send(result)
})

//修改审核状态
router.put("/upDateStatus",async function(req,res,next){
    // console.log("第一层"+req.body);
    const result=await upDate2(req.body);
    res.send(result)
})

//新增车辆信息
router.post("/add",async function(req,res,next){
    const result=await add2(req.body)
    res.send(result)
})

//下架车辆
router.put("/upDateRemoved",async function(req,res,next){
    const result=await upDateRemoved2(req.body)
    res.send(result)
})

module.exports = router;